package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.Utils.DateUtils;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.SetmealDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ReportServiceImpl
 * @Description: TODO
 * @Author 郑乾
 * @Date 2020-07-05
 * @Version V1.0
 **/
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    MemberDao memberDao;
    @Autowired
    OrderDao orderDao;
    @Autowired
    SetmealDao setmealDao;

    //reportDate:null,  统计时间（当前时间，今天）
    //todayNewMember :0,  今日新增会员数（注册时间为今天）
    //totalMember :0,     总会员数（）
    //thisWeekNewMember :0,  本周新增会员数( 注册时间 在周一以后即可)
    //thisMonthNewMember :0,  本月新增会员数( 注册时间 在1号以后即可)
    //todayOrderNumber :0,   今日预约数（今天有多少人预约要来体检（今日应该来多少人））
    //todayVisitsNumber :0,   今日到诊数（今日实际来了多少人）
    //thisWeekOrderNumber :0,   本周预约数（预约本周要来的人数（预约本周一到周日之间要来的人数））
    //thisWeekVisitsNumber :0,  本周到诊数（本周实际来了多少人（周一后实际到诊人数））
    //thisMonthOrderNumber :0,  本月预约数（预约本月要来的人数，预约1号到本月最后一天之间要来的人数））
    //thisMonthVisitsNumber :0,  本月到诊数（本月实际来了多少人（1号以后实际到诊人数））
    //hotSetmeal :热门套餐(前三)
    @Override
    public Map<String, Object> getBussinessReport() {
        //获取当前时间
        String todayDate = DateUtils.parseDate2String(new Date());
        //获取本周一日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekFirstDay());
        //获取本周日的日期
        String thisWeekSunday = DateUtils.parseDate2String(DateUtils.getThisWeekLastDay());
        //获取本月一号的日期
        String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getThisMonthFirstDay());
        //本月最后一天的日期
        String thisMonthLastDay = DateUtils.parseDate2String(DateUtils.getThisMonthLastDay());
        //统计时间 即今天
        String reportDate = todayDate;
        //今日注册会员数
        long todayNewMember = memberDao.findTodayNewMember(todayDate);
        //总会员数
        long totalMember = memberDao.findTotalCount();
        //本周新增会员数
        long thisWeekNewMember = memberDao.findCountByAfterDate(thisWeekMonday);
        //本月新增会员数
        long thisMonthNewMember = memberDao.findCountByAfterDate(thisMonthFirstDay);
        //今日预约数
        long todayOrderNumber = orderDao.findTodayOrderNumber(todayDate);
        //今日到诊数
        long todayVisitsNumber = orderDao.findTodayVisitsNumber(todayDate);
        //本周预约数
        long thisWeekOrderNumber = orderDao.findOrderNumberByBetweenDate(thisWeekMonday, thisWeekSunday);
        //本周到诊数
        long thisWeekVisitsNumber = orderDao.findVisitsNumberByAfterDate(thisWeekMonday);
        //本月预约数
        long thisMonthOrderNumber = orderDao.findOrderNumberByBetweenDate(thisMonthFirstDay, thisMonthLastDay);
        //本月到诊数
        long thisMonthVisitsNumber = orderDao.findVisitsNumberByAfterDate(thisMonthFirstDay);
        //热门套餐前三
        List<Map<String, Object>> hotSetmeal = setmealDao.getHotSetmeal();
        //创建返回值map
        Map<String, Object> map = new HashMap<>();
        map.put("reportDate", reportDate);
        map.put("totalMember", totalMember);
        map.put("todayNewMember", todayNewMember);
        map.put("thisWeekNewMember", thisWeekNewMember);
        map.put("thisMonthNewMember", thisMonthNewMember);
        map.put("todayOrderNumber", todayOrderNumber);
        map.put("todayVisitsNumber", todayVisitsNumber);
        map.put("thisWeekOrderNumber", thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber", thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
        map.put("hotSetmeal", hotSetmeal);
        return map;
    }
}
